#define _CRT_SECURE_NO_WARNINGS 1

#include "string.h"

void test_string1()
{
	HQ::string s1("Hello,world!");
	cout << s1.c_str() << endl;

	/*for (size_t i = 0; i < s1.size(); i++) {
		cout << ++s1[i] << " ";
	}*/

	/*HQ::string s2;
	cout << s2.c_str() << endl;*/

	/*for (const auto& ch : s1)
	{
		cout << ch << " ";
	}
	cout << endl;*/

	//// 封装：屏蔽了底层实现细节，提供了一种简单通用访问容器的方式
	//HQ::string::iterator it1 = s1.begin();
	//while (it1 != s1.end())
	//{  
	//	cout << *it1 << " ";
	//	++it1;
	//}
	//cout << endl;

/*	HQ::string::const_iterator it2 = s1.begin();
	while (it2 != s1.end())
	{  
		cout << *it2 << " ";
		++it2;
	}
	cout << endl*/;
}

void test_string2()
{
	HQ::string s1("Hello,world!");
	cout << s1.c_str() << endl;

	s1.push_back('x');
	s1.push_back('x');
	cout << s1.c_str() << endl;

	s1.append("haha");
	cout << s1.c_str() << endl;

}

void test_string3()
{
	HQ::string s1("Hello,world!");
	cout << s1.c_str() << endl;

	s1 += '!';
	cout << s1.c_str() << endl;

	s1 += "Oh~Oh~";
	cout << s1.c_str() << endl;
}

void test_string4()
{
	HQ::string s1("Hello,world!");
	cout << s1.c_str() << endl;

	s1.insert(5, '~');
	cout << s1.c_str() << endl;

	s1.insert(0, 'x');
	cout << s1.c_str() << endl;
}

void test_string5()
{
	HQ::string s1("Hello,world!");
	cout << s1.c_str() << endl;

	s1.insert(0, "xxx");
	cout << s1.c_str() << endl;

}

void test_string6()
{
	HQ::string s1;
	cout << s1.c_str() << endl;

	s1 += "Hello ";
	cout << s1.c_str() << endl;

	s1.insert(6, "World!");
	cout << s1.c_str() << endl;

}

void test_string7()
{
	HQ::string s1("Hello,world!");
	cout << s1.c_str() << endl;

	s1.erase(5, 3);
	cout << s1.c_str() << endl;
}

void test_string8()
{
	HQ::string s1("Hello,world!");
	cout << s1.c_str() << endl;

	cout << s1.find('o') << endl;
	cout << s1.find("word") << endl;
}

void test_string9()
{
	HQ::string s1("Hello,world!");
	HQ::string s2(s1);

	cout << s1.c_str() << endl;
	cout << s2.c_str() << endl;
}

void test_string10()
{
	HQ::string s1("Hello,world!");
	HQ::string s2;

	s2 = s1;

	cout << s1.c_str() << endl;
	cout << s2.c_str() << endl;
}

void test_string11()
{
	HQ::string s1("Hello,world!");
	HQ::string s2("hello,world!");

	cout << "交换前:" << endl;
	cout << s1.c_str() << endl;
	cout << s2.c_str() << endl;

	s1.swap(s2);

	cout << "交换后:" << endl;
	cout << s1.c_str() << endl;
	cout << s2.c_str() << endl;
}

void test_string12()
{
	HQ::string s1("Hello,world!");
	HQ::string s2;

	s2 = s1.substr(0, 5);

	cout << s1.c_str() << endl;
	cout << s2.c_str() << endl;
}

void test_string13()
{
	HQ::string s1("Hello,world!");

	cin >> s1;
	cout << s1;
}

int main()
{
	test_string13();

	


	return 0;
}
